/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-04
 * Time: 22:01
 */
public class test4 {
    /**
     * LeetCode 680 验证回文串II
     */

    public boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length()-1;
        while(left<right){
            char c1 = s.charAt(left);
            char c2 = s.charAt(right);
            if(c1==c2){
                left++;
                right--;
            }else{
                // 遇到不同的
                // 左边删一个或者右边删一个之后再继续判断回文
                return validPalindrome(s,left,right-1) || validPalindrome(s,left+1,right);
            }
        }
        return true;
    }

    public boolean validPalindrome(String s,int left,int right){
        for(int i=left,j=right;i<j;i++,j--){
            char c1 = s.charAt(i);
            char c2 = s.charAt(j);
            if(c1!=c2){
                return false;
            }
        }
        return true;
    }
}
